package com.bmadmin.controller.cus;

import com.bmadmin.domain.DataCustTableBodyPOJO;
import com.bmadmin.domain.DataCustTableHeadPOJO;
import com.bmadmin.domain.LayUiDataTablePOJO;
import com.bmadmin.domain.NormalResult;
import com.bmadmin.service.DataTableForCustomerService;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 用户自建表管理
 */
@RestController
@RequestMapping(value = "/datatableForCustomer")
public class DataTableForCustomerController {
    private Logger logger = LogManager.getLogger(this.getClass().getName());

    @Autowired
    DataTableForCustomerService dataTableForCustomerService;

    /**
     * 获取用户自建表列表（树）
     * @return
     */
    @GetMapping(value = "/getDataTableForCustomerList")
    public NormalResult getDataTableForCustomerList(){
        NormalResult tableList = dataTableForCustomerService.getTableList();
        logger.info(tableList);
        return tableList;
    }

    /**
     * 根据t_id 获取数据表头信息
     * @param dataCustTableHeadPOJO
     * @return
     */
    @GetMapping(value = "/getDataTableHeadById")
    public NormalResult getDataTableHeadById(DataCustTableHeadPOJO dataCustTableHeadPOJO){
        NormalResult result = new NormalResult();

        result = dataTableForCustomerService.getTableHeadByTableId(dataCustTableHeadPOJO);
        logger.info(result);
        return result;
    }

    /**
     * 根据t_id 获取数据表详细信息
     * @param dataCustTableBodyPOJO
     * @return
     */
    @GetMapping(value = "/getDataTableBodyByTid")
    public LayUiDataTablePOJO getDataTableBodyByTid(DataCustTableBodyPOJO dataCustTableBodyPOJO){
        LayUiDataTablePOJO result = new LayUiDataTablePOJO();
        result = dataTableForCustomerService.getTableBodyByTableId(dataCustTableBodyPOJO);

        logger.info(result);
        return result;
    }

    /**
     * 新增自建表-表头
     * @param dataCustTableHeadPOJO
     * @return
     */
    @PostMapping(value = "/insertTableHead",produces = "application/json")
    public NormalResult insertTableHead(@RequestBody DataCustTableHeadPOJO dataCustTableHeadPOJO){
        return dataTableForCustomerService.insertTableHead(dataCustTableHeadPOJO);
    }

    /**
     * 删除自建表-整表
     * @param dataCustTableHeadPOJO
     * @return
     */
    @PostMapping(value = "/deleteTableHeadAndBody",produces = "application/json")
    public NormalResult deleteTableHeadAndBOdy(@RequestBody DataCustTableHeadPOJO dataCustTableHeadPOJO){
        return dataTableForCustomerService.deleteTableHeadAndBody(dataCustTableHeadPOJO);
    }

    /**
     * 修改自建表-表头
     * @param dataCustTableHeadPOJO
     * @return
     */
    @PostMapping(value = "/updateTableHead",produces = "application/json")
    public NormalResult updateTableHead(@RequestBody DataCustTableHeadPOJO dataCustTableHeadPOJO){
        return dataTableForCustomerService.updateTableHead(dataCustTableHeadPOJO);
    }

    /**
     * 新增自建表-表体
     * @param dataCustTableBodyPOJO
     * @return
     */
    @PostMapping(value = "/insertTableBody",produces = "application/json")
    public NormalResult insertTableBody(@RequestBody DataCustTableBodyPOJO dataCustTableBodyPOJO){
        return dataTableForCustomerService.insertTableBody(dataCustTableBodyPOJO);
    }

    /**
     * 删除自建表-表体
     * @param dataCustTableBodyPOJO
     * @return
     */
    @PostMapping(value = "/deleteTableBody",produces = "application/json")
    public NormalResult deleteTableBody(@RequestBody DataCustTableBodyPOJO dataCustTableBodyPOJO){
        return dataTableForCustomerService.deleteTableBody(dataCustTableBodyPOJO);
    }

    /**
     * 修改自建表-表体
     * @param dataCustTableBodyPOJO
     * @return
     */
    @PostMapping(value = "/updateTableBody",produces = "application/json")
    public NormalResult updateTableBody(@RequestBody DataCustTableBodyPOJO dataCustTableBodyPOJO){
        return dataTableForCustomerService.updateTableBody(dataCustTableBodyPOJO);
    }

}
